﻿@model IEnumerable<NHibernateDemo.DAL.Entity.PersonBasic>
@{
    ViewBag.Title = "PersonList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
    PersonList</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            First Name
        </th>
        <th>
            Last Name
        </th>
        <th>
            Age
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name.FirstName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name.LastName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Age)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                <a href="javascript:void(0)" onclick="deleteThisPerson(this,'@Url.Action("Delete", new { id = item.PersonId })')">Delete</a>|
                @Html.ActionLink("Manage", "ManageList", "Management", new { name = item.Name.PassportName }, null)
            </td>
        </tr>
    }
</table>

<script type="text/javascript">
    function deleteThisTd(ele) {
        var td = $(ele).parent("td");
        td.parent().remove();
    }
    function deleteThisPerson(ele,url) {
        $.post(url, null,
        function (data) {
            if (data.success) {
                deleteThisTd(ele);
            } else {
                alert(data.msg);
            }
        },
        'json');
    }
</script>
